﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sekretar.DataLayer;

namespace Sekretar.Repository
{
    public class ROpstina : BaseRepository, InterfaceRepository<DataLayer.Opstina>
    {
 
        public IQueryable<DataLayer.Opstina> VratiSve()
        {
            dc = new SekretarDataContext();
            return dc.Opstinas;
        }

        public DataLayer.Opstina Nov()
        {
            this.jeNov = true;

            Opstina opstina = new Opstina();
            opstina.Status = true;
            opstina.KorisnikId = Common.Properties.Settings.Default.KorisnikId;
            opstina.DatumRada = Common.Tools.SqlFunkcije.VratiTrenutnoVreme();

            return opstina;
        }

        public DataLayer.Opstina Izmeni(int id)
        {
            return dc.Opstinas.SingleOrDefault(c => c.OpstinaId == id);
        }

        public int Snimi(Opstina opstina)
        {
            if (this.jeNov)
                dc.Opstinas.InsertOnSubmit(opstina);
            dc.SubmitChanges();
            return opstina.OpstinaId;
        }

        public void Brisi(int id)
        {
            dc.Opstinas.DeleteOnSubmit(dc.Opstinas.SingleOrDefault(c => c.OpstinaId == id));
            dc.SubmitChanges();
        }

        public IQueryable<DataLayer.Opstina> VratiSveAktivne()
        {
            dc = new SekretarDataContext();
            return dc.Opstinas.Where(s => s.Status == true);
        }
    }
}
